﻿using System;
using Castle.DynamicProxy;

namespace Mvvm.Common.Aop
{
    /// <summary>
    /// Aop拦截类
    /// <para>bb 2020-05-08 17:17:23</para>
    /// </summary>
    internal class AopInterceptor : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            Action<IInvocation> action = invocation1 => invocation1.Proceed();

            foreach (AopBaseAttribute attr in invocation.Method.GetCustomAttributes(typeof(AopBaseAttribute), false))
            {
                AopExtensions.InjectProperties(attr);
                action = attr.Invoke(action);
            }

            action.Invoke(invocation);
        }
    }
}